package logic

import (
	"context"
	"gorm.io/gorm"
	"wechat/wechatrpc/models/mysql"

	"wechat/wechatrpc/internal/svc"
	"wechat/wechatrpc/wechatrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PerfectLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPerfectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PerfectLogic {
	return &PerfectLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PerfectLogic) Perfect(in *wechatrpc.PerfectRequest) (*wechatrpc.PerfectResponse, error) {
	// todo: add your logic here and delete this line

	var user mysql.User
	mysql.DB.Debug().Where("id=?", in.Id).Find(&user)

	users := mysql.User{
		Model:   gorm.Model{ID: uint(in.Id)},
		Image:   in.Image,
		Name:    in.Name,
		Address: in.Address,
	}
	mysql.DB.Debug().Updates(&users)
	return &wechatrpc.PerfectResponse{
		Id: int64(users.ID),
	}, nil
}
